﻿/*----------------------------------------------------------------
// Copyright (C) 2009 
// 版权所有。 
//
// 文件名：
// 文件功能描述：设备维修信息查询
//
//
// 创建标识：
// 程序作者：翟允锋
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using System.Threading;
using EQT.Model;
using Wuqi.Webdiyer;

public partial class EquipMtQuery : System.Web.UI.Page
{
    private static readonly Common.Logging.ILog log = Common.Logging.LogManager.GetCurrentClassLogger();
    private DaEquipMaintainLog dalMt = DevFuture.Common.WorkContext.AppCtx.GetObject("DaEquipMaintainLog") as DaEquipMaintainLog;
    private UserContext context;

    protected void Page_Load(object sender, EventArgs e)
    {
        context = Session["USER_CONTEXT"] as UserContext;
        OperationResult.Text = "";
        divResult.Visible = false;
        AspNetPager.PageSize = 15;

        if (!IsPostBack)
        {
            this.SetPanelVisiable(SummaryPanel);
            this.BtnQuery_Click(null, null);
        }
    }

    protected void AspNetPager_PageChanged(object sender, EventArgs e)
    {
        this.BtnQuery_Click(null, null);
    }

    protected void BtnQuery_Click(object sender, EventArgs e)
    {
        int pagecount = 0;
        string strCondition = "where 1=1 ";
        if (sender != null && e != null)
        {
            AspNetPager.CurrentPageIndex = 0;
        }

        if (!string.IsNullOrEmpty(TxtEquipID.Text.Trim()))
        {
            strCondition = strCondition + "and  Equip_ID='" + TxtEquipID.Text.Trim() + "'";
        }
        
        this.GridView.DataSource = dalMt.GetEquipMtRecords(strCondition, AspNetPager.PageSize, AspNetPager.CurrentPageIndex - 1, out pagecount);
        GridView.DataBind();

        AspNetPager.RecordCount = pagecount;
        this.SetPanelVisiable(SummaryPanel);
    }

    protected void BtnExport_Click(object sender, EventArgs e)
    {
        string strCondition = "where 1=1 ";

        if (!string.IsNullOrEmpty(TxtEquipID.Text.Trim()))
        {
            strCondition = strCondition + "and  Equip_ID='" + TxtEquipID.Text.Trim() + "'";
        }

        DataSet ds = dalMt.GetEquipMtRecords(strCondition);

        GridViewExport.DataSource = ds;
        GridViewExport.DataBind();

        GridViewExportUtil.Export("MaintainRecords.xls", GridViewExport);
        GridViewExport.DataSource = null;
        GridViewExport.DataBind();
    }

    protected void GvDetail_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;
        string strKey = ((GridView)gvr.NamingContainer).DataKeys[gvr.RowIndex].Value.ToString();

        this.DisplayDetailInfo(strKey);
        this.SetPanelVisiable(DetailPanel);
    }

    protected void DetailBack_Click(object sender, EventArgs e)
    {
        this.SetPanelVisiable(SummaryPanel);
    }

    private void DisplayDetailInfo(string strKey)
    {
        DetailEqui_Mtn_ID.Text = "";
        DetailEquip_ID.Text = "";
        DetailFullName.Text = "";
        DetailEmp_ID.Text = "";
        DetailMtn_Date.Text = "";
        DetailMtn_Info.Text = "";
        DetailEquip_Name.Text = "";

        DataSet ds = dalMt.GetMtDetail(strKey);
        if (ds.Tables[0].Rows.Count > 0)
        {
            DetailEqui_Mtn_ID.Text = ds.Tables[0].Rows[0]["Equi_Mtn_ID"].ToString();
            DetailEquip_ID.Text = ds.Tables[0].Rows[0]["Equip_ID"].ToString();
            DetailEmp_ID.Text = ds.Tables[0].Rows[0]["Emp_ID"].ToString();
            DetailFullName.Text = ds.Tables[0].Rows[0]["FullName"].ToString();
            DetailMtn_Date.Text = ds.Tables[0].Rows[0]["Mtn_Date"].ToString();
            DetailMtn_Info.Text = ds.Tables[0].Rows[0]["Mtn_Info"].ToString();
            DetailEquip_Name.Text = ds.Tables[0].Rows[0]["Equip_Name"].ToString();
        }
    }

    protected void SetPanelVisiable(Panel panel)
    {
        DetailPanel.Visible = false;
        SummaryPanel.Visible = false;

        panel.Visible = true;
    }
}
